home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / shell / xd-2.08 / xd-2 / xd / Match / Match.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-30  |  1.8 KB  |  84 lines

  1. #include <stdio.h> 
  2. #include "Match.h"
  3.  
  4. Match::Match(char const *pattern, Config const &cf)
  5.     :ICString()
  6. {
  7.     glob_struct.gl_pathc = 0;
  8.     glob_struct.gl_pathv = 0;        // very simple glob()
  9.  
  10.     extra_glob.gl_pathc = 0;        // initialize extra globbing-count
  11.     extra_glob.gl_pathv = 0;        // (for the destructor)
  12.  
  13.     glob(pattern, 0, 0, &glob_struct);    // no special flags,
  14.                      // the glob_struct tells
  15.                     // the story
  16.                     
  17. #ifdef DEBUG
  18.     fprintf(stderr, "Match::Match():\t Pattern: %s\n", pattern);
  19. #endif
  20.     
  21. /*
  22.     Options now:
  23.     1. The pattern doesn't start with HOME: no extra search required
  24.     Otherwise:
  25.         2. extraparam == Config::single_search:    no extra search
  26.         else
  27.         3. extraparam == Config::full_search:   extra search
  28.         else
  29.         4. extraparam == Config::double_search is implied.
  30.            If now gl_pathc == 0, then do extra search
  31.  
  32.     So, extra search only if
  33.     1. pattern doesn't start with $HOME
  34.     and
  35.         2. extraparam == full_search
  36.         or
  37.         3. extraparam == double_search
  38.         and
  39.         4. glob() didn't find anything.
  40. */
  41.                     // test conditions 1 and 2. If not,
  42.                     // double search may be needed
  43.  
  44.     register unsigned
  45.     home_length;
  46.  
  47.     register Config::ConfigExtra
  48.     extraparam = cf.get_extraparam();
  49.     
  50.     if
  51.     (
  52.     !strncmp (pattern, cf.get_home(), home_length = strlen(cf.get_home()))
  53.     &&
  54.     (
  55.         extraparam == Config::full_search
  56.         ||
  57.         (
  58.         extraparam == Config::double_search
  59.         &&
  60.         !glob_struct.gl_pathc
  61.         )
  62.     )
  63.     )
  64.     glob(pattern + home_length - 1, 0, 0, &extra_glob);    // no special flags,
  65.  
  66. #ifdef DEBUG
  67.     fprintf(stderr, "Match::Match():\t Pattern2: %s\n",
  68.                 pattern + home_length - 1);
  69. #endif
  70.     
  71.     unsigned
  72.     count = 
  73.         add_globbed(glob_struct)
  74.         +
  75.         add_globbed(extra_glob);
  76.  
  77. #ifdef DEBUG
  78.     if (!count)
  79.     fprintf(stderr, "Match::Match():\t glob(): no joy\n");
  80. #endif
  81.  
  82. }
  83.  
  84.